﻿using System;
using System.Collections.Generic;
using System.Text;

namespace HBKY.Shop.Model
{
    public class CommonResult<T>
    {
        public CommonResult(int cd, string msg, T d)
        {
            Code = cd;
            Message = msg;
            Data = d;
        }
        public int Code { get; set; }
        public string Message { get; set; }
        public T Data { get; set; }
        public bool IsSuccess { get { return Code == 1; } }
        public static CommonResult<T> Success(string message, T data = default(T))
        {
            return new CommonResult<T>(1, message, data);
        }
        public static CommonResult<T> Success(T data = default(T))
        {
            return new CommonResult<T>(1, "成功", data);
        }
        public static CommonResult<T> Fail(string message = "失败", T data = default(T))
        {
            return new CommonResult<T>(0, message, data);
        }
        public static CommonResult<T> Exception(T data = default(T))
        {
            return new CommonResult<T>(-1, "异常", data);
        }
    }
}
